package NGUYENVANDOAN.XMLDEMO.SAMPLE;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;

public class frmReadFiles extends JFrame {

    private final JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    frmReadFiles frame = new frmReadFiles();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public frmReadFiles() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JButton btnNewButton = new JButton("Read files");
        btnNewButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                JFileChooser objFile = new JFileChooser();
                objFile.setCurrentDirectory(new java.io.File("."));
                objFile.setDialogTitle("Chọn file: ");
                objFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                String[] EXTENSION = new String[] { "xml" };
                FileNameExtensionFilter filter = new FileNameExtensionFilter("XML files", EXTENSION);
                objFile.setFileFilter(filter);
                objFile.setMultiSelectionEnabled(false);

                int returnVal = objFile.showOpenDialog(getParent());
                String ParentPath = "";
                String FileName = "";
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    ParentPath = objFile.getSelectedFile().getParent();
                    FileName = objFile.getSelectedFile().getName();
                }
            }
        });
        btnNewButton.setBounds(10, 11, 208, 33);
        contentPane.add(btnNewButton);
    }
}
